import { PoolManager } from 'db://assets/Scripts/Framework/Managers/PoolManager';
import { InGameManager } from '../Managers/InGameManager';
import { Weapon } from './Weapon';
import { Module } from './Module';

export class Gun extends Weapon {

    canUse: boolean = true;
    //类型
    type: number;
    //爆头倍率
    headShotMultiply: number;
    //散布
    spread: number;
    //最大散布
    maxSpread: number;
    //后坐力
    recoil: number;
    //后坐力恢复
    recoilRecovery: number;
    //当前弹药量
    curAmmo: number;
    //最大弹药量
    maxAmmo: number;
    //弹丸数量
    bullet: number;
    //配件
    modules: Module[] = [null, null, null, null, null];
    //可装配配件
    accessModules: boolean[];

    static Init(_type: number, _num: number): Gun {
        let data = InGameManager.itemsJson.Gun[_type][_num];
        let gun = PoolManager.GetItem(Gun);
        gun.num = 1;
        gun.type = _type;
        gun.itemName = data.name;
        gun.maxAmmo = data.maxAmmo;
        gun.curAmmo = gun.maxAmmo;
        gun.damage = data.damage;
        gun.headShotMultiply = data.headShotMultiply;
        gun.armorExpose = data.armorExpose;
        gun.rate = data.rate;
        gun.spread = data.spread;
        gun.maxSpread = data.maxSpread;
        gun.recoil = data.recoil;
        gun.recoilRecovery = data.recoilRecovery;
        gun.bullet = data.bullet;
        switch (_type) {
            case 0:
                gun.accessModules = [true, false, true, false, false];
                break;
            case 1:
                gun.accessModules = [true, true, true, true, true];
                break;
            case 2:
                gun.accessModules = [true, true, false, false, true];
                break;
            case 3:
                gun.accessModules = [true, true, true, false, true];
                break;
            case 4:
                gun.accessModules = [true, false, false, false, true];
                break;
        }
        gun.sfUrl = data.spriteFrame;
        gun.weaponSfUrl = data.weaponSpriteFrame;
        gun.prefabUrl = data.prefab;
        return gun;
    }

}